// ignore_for_file: public_member_api_docs, sort_constructors_first
class LastMessageModel {
  final String username;
  final String profileImageUrl;
  final String contactId;
  final DateTime timeSent;
  final String lastMessage;

  LastMessageModel({
    required this.username,
    required this.profileImageUrl,
    required this.contactId,
    required this.timeSent,
    required this.lastMessage,
  });

  Map<String, dynamic> toMap() {
    return {
      'username': username,
      'profileImageUrl': profileImageUrl,
      'contactId': contactId,
      'timeSent': timeSent.millisecondsSinceEpoch,
      'lastMessage': lastMessage,
    };
  }

  factory LastMessageModel.fromMap(Map<String, dynamic> map) {
    return LastMessageModel(
      username: map["username"] ?? '',
      profileImageUrl: map["profileImageUrl"] ?? '',
      contactId: map["contactId"] ?? '',
      timeSent: DateTime.fromMillisecondsSinceEpoch(map["timeSent"]),
      lastMessage: map["lastMessage"] ?? '',
    );
  }
}
